<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/CogDataSet">
		<xsl:for-each select="TableInfo">
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[<xsl:value-of select="Schema"/>].[<xsl:value-of select="ManagedTable"/>_Select]'))
DROP VIEW [<xsl:value-of select="Schema"/>].[<xsl:value-of select="ManagedTable"/>_Select]
GO

CREATE VIEW [<xsl:value-of select="Schema"/>].[<xsl:value-of select="ManagedTable"/>_Select]
AS
SELECT <xsl:for-each select="ColumnInfo">[<xsl:value-of select="Column"/>]<xsl:if test="not(position()=last())">,
	</xsl:if></xsl:for-each>
FROM [<xsl:value-of select="Schema"/>].[<xsl:value-of select="Table"/>]
GO
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
